package de.rankyman.tools;

import java.util.ArrayList;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class RegExMatcher {
	
	private Pattern pattern;
	private Matcher matcher;
	
	public RegExMatcher(String regex) {
		setPattern(regex);
	}
	
	public void setPattern(String regex) {
		pattern = Pattern.compile(regex);
	}
	
	public List<String> match(String input) {
		List<String> list = new ArrayList<String>();
		matcher = pattern.matcher(input);
		
		if (matcher.find()) {
			int count = matcher.groupCount();
			for (int i = 1; i <= count; i++) {
				list.add(matcher.group(i));
			}
		}
		
		return list;
	}
}
